<template>
	<view style="background-color: #f9f9f9;">
		<!-- <view class="set">
			<text class="iconfont"  @tap="toSet()" style="float:right;margin-right:25upx;font-size: 40rpx;">&#xe606;</text>
		</view> -->
		<view class="main-bg-color position-relative" style="height: 350upx;">
			<view style="width: 100%;height: 100rpx;"></view>
			<view class="row main-text-color-bai a-center j-sb" style="height: 130upx;">
				<view class="row a-center" style="height: 126upx;margin-left: 30rpx;">
					<image :src="headimgurl" style="width: 126upx;height: 126upx;border-radius: 50%;overflow: hidden;"></image>
					<view class="pl-2">
						<view class="">
							{{nickname}}
						</view>
						<view class="">
							{{identity_type}}
						</view>
					</view>
				</view>
				<!-- <navigator url="../membercenter/membercenter" class="row a-center px-2" style="border-radius: 30upx;border: 1px solid #8db9ff;">
					<text>编辑资料</text>
					<image src="../../static/rssd01.png" style="width: 16upx;height: 24upx;margin-left: 10rpx;"></image>
				</navigator> -->
				<view @tap="store_apply()" class="apply-agent">
					<text>门店申请</text>
				</view>
			</view>
			<!-- <view @tap="shoping()" class="position-absolute bottom-0 px-3 py-2 main-text-color-bai font-md" style="background-color: #52c41a;border-radius: 50upx 50upx 0 0;width: 633upx;left: 30upx;">
				谷雨颐嘉积分商城
			</view> -->
		</view>
		<view class="row j-center a-center" style="height: 145upx;justify-content:space-around;">
			<view class="px-5  row flex-column a-center ">
				<view class="text-center f_a">{{myScores.score}}</view>
				<view class="">可提金额</view>
			</view>
			<view class="px-5 ">
				<view class="text-center f_a">{{myScores.withdrawing_money}}</view>
				<view class="">在提金额</view>
			</view>
			<view class="px-5 ">
				<view class="text-center f_a">{{myScores.withdrawed_money}}</view>
				<view class="">已提金额</view>
			</view>
		</view>
		<view class="main-bg-color-bai p-3 mb-2 rounded radius" style="margin-top: 30rpx;">
			<view class="row j-sb a-center">
				<text class="font-md font-weight-6">我的订单</text>
				<!-- <text @tap="allOrder()">全部订单</text> -->
			</view>
			<view class="tool">
				
				<block v-for="(item,index) in resdata" :key="index">
					<view  class="tool-item"
					@tap="event(item)">
						<image :src="item.src" style="width: 80upx;height: 80upx;" mode=""></image>
						<text style="font-size: 28rpx;">{{item.text}}</text>
					</view>
				</block>
				
			</view>
		</view>
		<view class="main-bg-color-bai p-3 rounded radius mt_50">
			<view class="font-md font-weight-6">
				常用工具
			</view>
			<view class="tool">
				
				<view class="tool-item" @tap="scorecenter()">
					<image src="../../static/score.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">积分中心</text>
				</view>
				<view class="tool-item" @tap="intro()">
					<image src="../../static/tools02.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">关于我们</text>
				</view>
				<view class="tool-item" @tap="agent()">
					<image src="../../static/tools04.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">门店</text>
				</view>
				<view class="tool-item" @tap="distribution()">
					<image src="../../static/tools05.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">分销中心</text>
				</view>
			</view>
			<view class="tool mt_50">
				<view class="tool-item" @click="tel()">
					<image src="../../static/tools03.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">联系我们</text>
				</view>
				<view class="tool-item" @tap="edit_user()">
					<image src="../../static/tools06.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">编辑资料</text>
				</view>
				<view class="tool-item" @tap="dis_qrcode()">
					<image src="../../static/tools07.png" 
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">二维码</text>
				</view>
				<view class="tool-item" @tap="toSet()">
					<image src="../../static/tools08.png"
					 style="width: 80upx;height: 80upx;"
					mode="" class="mb-2"></image>
					<text style="font-size: 28rpx;margin-top: 10rpx;">系统设置</text>
				</view>
			</view>
		</view>
		<view style="width: 100%;height: 200rpx;">
			
		</view>
	</view>
</template>

<script>
	import request from '@/common/lib/request.js'
	export default {
		data() {
			return {
				carts: [],
				myScores:'',
				nickname:'',
				headimgurl:'',
				identity_type:'',
				resdata:[
				{
					state:1,
					src:'../../static/orderlist1.png',
					text:'待付款'
				},
				{
					state:2,
					src:'../../static/orderlist2.png',
					text:'待体检'
				},
				{
					state:3,
					src:'../../static/orderlist3.png',
					text:'已体检'
				},
				{
					state:0,
					src:'../../static/orderlist4.png',
					text:'全部'
				}]
			}
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			uni.setNavigationBarTitle({
				title: '个人中心'
			});
		},
		methods: {
			toSet(){
				uni.navigateTo({
					url:'../login/set'
				})
			},
			edit_user(){
				uni.navigateTo({
					url:'../membercenter/membercenter'
				})
			},
			dis_qrcode(){
				uni.navigateTo({
					url:'../distribution/qrcode'
				})
			},
			allOrder(){
				uni.navigateTo({
					url:"../orderlist/orderlist"
				})
			},
			event(item){
				uni.navigateTo({
					url:"../orderlist/orderlist?state="+item.state
				})
			},
			intro(){
				uni.navigateTo({
					url:"/pages/intro/intro"
				})
			},
			shoping(){
				uni.navigateTo({
					url:"/pages/score/scoreshop?scores="+this.myScores.score
				})
			},
			scorecenter(){
				uni.navigateTo({
					url:"/pages/score/score?scores="+this.myScores.score
				})
			},
			//拨打电话
			tel() {
				uni.request({
				    url: request.common.baseUrl+'/api/index/systemSet',
				    data: {},
				    header: {
						'Content-Type':'application/json;charset=UTF-8',
						'Content-Type':'application/x-www-form-urlencoded'
				    },
				    success: (res) => {
						uni.makePhoneCall({
							phoneNumber:res.data.data.contactus //仅为示例
						});
				    }
				});
				
			},
			getMyCarts() {
				uni.request({
					url: request.common.baseUrl+'/api/cart/myCarts',
					data: {
						page: 1,
						token:uni.getStorageSync('keyToken')
					},
					header: {
						'Content-Type':'application/json;charset=UTF-8',
						'Content-Type':'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if(res.data.code == 200){
							this.carts = res.data.data
						}else{
							this.carts = []
						}
						if(this.carts.length){
							uni.setTabBarBadge({
							  index: 2,
							  text: JSON.stringify(this.carts.length),
							})
						}else{
							uni.removeTabBarBadge({
								index: 2,
							})
						}
					}
				})
			},
			agent(){
				if(this.identity_type=='服务商'){
					uni.navigateTo({
						url:"/pages/agent/myagents"
						// url:"/pages/agent/manage"
					})
				}else{
					uni.showToast({
					    title: '您不是门店服务商',
						icon: 'none',
					    duration: 2000
					});
				}
				
			},
			store_apply(){
				if(this.identity_type=='普通'){
					uni.navigateTo({
						url:"/pages/agent/apply"
					})
				}else if(this.identity_type=='会员'){
					uni.navigateTo({
						url:"/pages/agent/apply"
					})
				}else if(this.identity_type=='服务商'){
					uni.navigateTo({
						url:"/pages/agent/apply"
					})
				}else{
					uni.showToast({
					    title: '您没有权限',
						icon: 'none',
					    duration: 2000
					});
				}
			},
			distribution(){
				if(this.identity_type=='会员'||this.identity_type=='服务商'||this.identity_type=='推广商'){
					uni.navigateTo({
						url:"/pages/distribution/my"
					})
				}else{
					uni.showToast({
					    title: '您不是会员或服务商',
						icon: 'none',
					    duration: 2000
					});
				}
			}
		},
		onShow() {
			if(uni.getStorageSync('keyToken')){
				this.getMyCarts()
				// if(uni.getStorageSync('keyIdentity_type')){
				// 	this.nickname=uni.getStorageSync('keyNickname');
				// 	this.headimgurl=uni.getStorageSync('keyHeadimgurl');
				// 	this.identity_type=uni.getStorageSync('keyIdentity_type');
				// }else{
					uni.request({
						url: request.common.baseUrl+'/api/users/userinfos',
						data: {
							token:uni.getStorageSync('keyToken')
						},
						header: {
							'Content-Type':'application/json;charset=UTF-8',
							'Content-Type':'application/x-www-form-urlencoded'
						},
						success: (res) => {
							if(res.data.code==200){
								this.nickname=res.data.data.nickname
								this.headimgurl=res.data.data.headimgurl
								if(res.data.data.identity_type==1){
									this.identity_type='普通'
									uni.removeStorageSync('keyDiscount')
								}else if(res.data.data.identity_type==2){
									this.identity_type='会员'
									uni.setStorageSync('keyDiscount',9)//会员在线商品九折优惠
								}else if(res.data.data.identity_type==3){
									this.identity_type='服务商'
									uni.removeStorageSync('keyDiscount')
								}else if(res.data.data.identity_type==4){
									this.identity_type='推广商'
									uni.removeStorageSync('keyDiscount')
								}
							}
						}
					});
				// }
				uni.request({
					url: request.common.baseUrl+'/api/distributor/myScore',
					data: {
						token:uni.getStorageSync('keyToken')
					},
					header: {
						'Content-Type':'application/json;charset=UTF-8',
						'Content-Type':'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if(res.data.code==200){
							this.myScores=res.data.data
						}
					}
				});
			}else{
				uni.navigateTo({
					url:'/pages/login/login'
				})
			}
		}
	}
</script>

<style>
	page{
		background-color:rgb(249, 249, 249);
	}
	@font-face {
	  font-family: 'iconfont';
	  src: url('@/static/font/iconfont.eot');
	  src: url('@/static/font/iconfont.eot?#iefix') format('embedded-opentype'),
		  url('@/static/font/iconfont.woff2') format('woff2'),
		  url('@/static/font/iconfont.woff') format('woff'),
		  url('@/static/font/iconfont.ttf') format('truetype'),
		  url('@/static/font/iconfont.svg#iconfont') format('svg');
	}
	.iconfont {
	  font-family: "iconfont" !important;
	  font-size: 34upx;
	  font-style: normal;
	  -webkit-font-smoothing: antialiased;
	  -moz-osx-font-smoothing: grayscale;
	}
	.set{
		position:fixed;
		z-index:1;
		width:750upx;
		height:92upx;
		background-color:#317bf2;
		color:#FFFFFF;
	}
	.radius{
		width: 690rpx;
		margin: 0 auto;
		border-radius: 30rpx;
		box-sizing: border-box;
	}
	.mt_50{
		margin-top: 50rpx;
	}
	.f_a{
		font-family: Arial, Helvetica, sans-serif;
		font-size: 36rpx;
		font-weight: bold;
	}
	.apply-agent {
		display: absolute;
		left: -30rpx;
		padding: 8rpx 20rpx;
		border-radius: 30rpx 0 0 30rpx;
		color: #FFFFFF;
		background-color: #FD6801;
	}
	.tool{
		width: 100%;
		display: flex;
		justify-content: space-between;
	}
	.tool-item{
		width: 120rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 40rpx;
	}
</style>
